import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/login.vue'
import Home from '../components/home.vue'
import Welcome from '../components/welcome.vue'
import OneDData from '../components/measureData/1dData.vue'
import TwoDData from '../components/measureData/2dData copy.vue'
import ModelShow from '../components/measureData/modelShow copy.vue'
import PicMeasure from '../components/measureData/PicMeasure.vue'
import OperateIndex from '../components/operate/index.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/home'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [{
      path: '/welcome',
      component: Welcome
    }, {
      path: '/measureData/1d',
      component: OneDData
    }, {
      path: '/measureData/2d',
      component: TwoDData
    }, {
      path: '/measureData/model',
      component: ModelShow
    }, {
      path: '/measureData/pic',
      component: PicMeasure
    }, {
      path: '/operate/index',
      component: OperateIndex
    }]
  }
]

const router = new VueRouter({
  routes
})

// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   // to表示要访问的路径
//   // from表示跳转的路径来源
//   // next是跳转函数,没有参数则表示放行

//   // 访问登录页面放行
//   if (to.path === '/login') return next()
//   // 访问其他页面要先验证token信息是否存在
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) return next('/login')
//   next()
// })

export default router
